var moment = require('moment');
var _ = require('underscore');

module.exports = function (app) {
  app.post('/mobile/http/stat/:appId/region', function (req, res) {
    res.status(200).json({
      "result": [
        {
          "combData": {
            "count": 76,
            "et": 1450889820000,
            "st": 1450852020000,
            "val": 127.103
          },
          "id": 21,
          "name": "360000"
        },
        {
          "combData": {
            "count": 10,
            "et": 1450889820000,
            "st": 1450852020000,
            "val": 10.012
          },
          "id": 31,
          "name": "150000"
        },
        {
          "combData": {
            "count": 305,
            "et": 1450889820000,
            "st": 1450852020000,
            "val": 249.504
          },
          "id": 8,
          "name": "330000"
        },
        {
          "combData": {
            "count": 5,
            "et": 1450889820000,
            "st": 1450852020000,
            "val": 3.096
          },
          "id": 45,
          "name": "610000"
        },
        {
          "combData": {
            "count": 123,
            "et": 1450889820000,
            "st": 1450852020000,
            "val": 59.064
          },
          "id": 47,
          "name": "650000"
        }
      ],
      "timeSpan": {
        "endTime": 1450853820000,
        "interval": 1800000,
        "startTime": 1450852020000
      }
    });
  });

  app.post('/mobile/http/stat/:appId/domain', function (req, res) {
    res.status(200).json({
      // 当且仅当 httpStatus为200时，不为空
      'data':[
        // 用户关注域名的统计
        {
            "avgResponseTime":760,//平均响应时间
            "day":1448812800000,//数据统计的时间
            "domainDesc":"百度",//用户关注的域名才有描述
            "domainId":108,//域名ID
            "domainName":"www.baidu.com",//域名URL
            "focusDomainId":108,//用户关注的域名
            "tendency":[844,1142,271,830]//变化趋势
        },
        //其他域名统计数据
        {
            "avgResponseTime":1023,
            "day":1448812800000,
            "domainId":1942,
            "domainName":"www.csdn.com",
            "tendency":[1012,2102,901,381,873]
        }
      ],
      "httpStatus":200,
      "msg":""
    });
  });

  app.post('/mobile/overview/ranking/:appId/performance', function (req, res) {
    if (req.params.appVersionId === 1) {
      res.status(200).json({"judgement":{"meaning":"无性能状况信息 ，今日无用户使用应用","name":"unuse","scoreDesc":"使用次数=0","title":"暂无使用数据"},"rankings":{"count.http":0,"count.http.net.error":0,"avg.activity.execute.time":0,"count.android.app.use":0,"count.activity.execute":0,"rate.error.network":0,"count.http.status.error.affectedUsers":0,"count.android.crash.affectedUsers":0,"rate.error.http":0,"rate.crash.android":0,"count.http.status.error":0,"count.http.net.error.affectedUsers":0,"count.android.crash":0},"score":0});
    } else
    res.status(200).json({
      "judgement": {
        "meaning": "检测耗时3s，检测8项性能指标，应用存在一些列问题，会影响APP使用",
        "name": "improvable",
        "scoreDesc": "得分 （<60）",
        "title": "今日检测性能状况较差"
      },
      "rankings": {
        "count.http": 0, // HTTP次数
        "count.http.net.error.affectedUsers": 0, // Http网络错误影响用户数
        "count.http.net.error": 0, // Http网络错误数
        "count.activity.block": 0, // 交互卡顿
        "count.activity.block.affectedUsers": 0, // 卡顿影响用户数
        "count.android.crash": 0, // 安卓崩溃次数
        "count.android.crash.affectedUsers": 0, // 安卓崩溃影响用户数
        "count.anr": 0, // ANR发生次数
        "count.anr.affectedUsers": 0, // ANR影响用户数
        "count.ios.crash":0, // Ios崩溃次数
        "count.ios.crash.affectedUsers":0, // Ios崩溃响用户数
        "count.http.status.error":0, // Http错误数
        "count.http.status.error.affectedUsers":0, // Http错误影响用户数
        "count.device.use": 0, // 使用APP次数
        "count.activity.slow": 0, // 慢trace发生次数
        "count.device.alive": 0 // 活跃用户数
      },
      "score": 86 // 体检分数
    });
  });

  app.post('/mobile/http/stat/:appId/range', function (req, res) {
    res.status(200).json({
      "result": [{
        "data": [{
          "count": 0,
          "et": 1451923200000,
          "leftBottom": "0",
          "max": 0,
          "min": 0,
          "percent": 1,
          "rightBottom": "60",
          "st": 1451836800000,
          "total": 0
        }],
        "key": {
          "id": 1,
          "name": "0-60"
        }
      }]
    });
  })
}
